package cn.edu.neusoft.yuejian4.yuejian_4.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.Config.Server;
import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.activity.GameDetailActivity;
import cn.edu.neusoft.yuejian4.yuejian_4.activity.MasterDetailActivity;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Master;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Recentgame;

/**
 * Created by Lix on 2018/10/18.
 */

public class MasterListAdapter extends RecyclerView.Adapter<MasterListAdapter.ViewHolder> {

    private List<Master> mMasters;
    private Context mContext;

    public MasterListAdapter(Context mContext, List<Master> mMasters){
        this.mContext = mContext;
        this.mMasters = mMasters;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public MasterListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.master_cardview,parent,false);
        MasterListAdapter.ViewHolder holder = new MasterListAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MasterListAdapter.ViewHolder holder, int position) {
        final Master master = mMasters.get(position);
        Picasso.with(mContext)
                .load(Server.PIC_URL_J+master.getPic())
                .placeholder(R.drawable.ic_default_img)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .into(holder.masterImg);

        holder.masterName.setText(master.getName());
        holder.masterInclub.setText(master.getClubname());
        holder.masterImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, MasterDetailActivity.class);
                intent.putExtra("master_id",master.getId());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mMasters.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView masterImg;
        TextView  masterName;
        TextView masterInclub;


        public ViewHolder(View view){
            super(view);
            masterImg= (ImageView)view.findViewById(R.id.master_img);
            masterName = (TextView)view.findViewById(R.id.master_name);
            masterInclub = (TextView)view.findViewById(R.id.master_shuyuclub);

        }
    }
}
